package com.jaws.demo.controller;

import com.jaws.demo.service.AccountServiceImpl;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * @author liangqm
 * @date 2018/4/19 8:22
 * @since v1.0.0
 */
@RestController
@RequestMapping("batch")
public class BatchDemoController {

	@Resource
	private JobLauncher jobLauncher;

	@Resource
	private Job importJob;

	public JobParameters jobParameters;

	@PostMapping("/imp")
	public String imp(String fileName) throws Exception {
		String path = fileName + ".csv";
		jobParameters = new JobParametersBuilder()
				.addLong("time", System.currentTimeMillis())
				.addString("input.file.name", path)
				.toJobParameters();

		jobLauncher.run(importJob, jobParameters);
		return "ok";
	}


}  